package com.flexandair.templates
{
	public class RemoteMethod
	{
		import mx.controls.Alert;
		private var _type:String = "";
		private var _dbName:String = "";
		private var _dbTable:String = "";
		public var _object:CustomObjectFile;
		
		private var _create:String = "";
		public function RemoteMethod()
		{
		}
		
		public function create(dbName:String, dbTable:String):void {
			var i:int = 0;
			var j:int = 0;
			var statement:String = "INSERT INTO `" + dbName + "`.`" + dbTable + "` (";
			for each (var property:ObjectProperty in _object.classProperties) {
				if (property.name == "id") {
					if (j == 0) {
					statement += "id";
					}
					else {
						statement += ", id";
					}
				}
				else {
					if (j == 0) {
						statement += " " + property.name;
					}
					else {
					statement += ", " + property.name;
					}
				}
				j++;
			}
			statement += ") VALUES (";
			for each (var property:ObjectProperty in _object.classProperties) {
				if (property.name == "id") {
					if (i == 0) {
					statement += "NULL";
					}
					else {
						statement += ", NULL";
					}
				}
				else {
					if (i == 0) {
						statement += "'$" + property.name + "'";
					}
					else {
						statement += ", '$" + property.name + "'";
					}
				}
				i++;
			}
			statement += ")";
			_create = statement;
			Alert.show(_create,"Insert Statement");
		}
	}
}